<template>
  <div class="pa">
    <el-card shadow="never" class="aui-card--fill">
      <div class="crud__menu">
        <el-col :span="12">
          <el-form :inline="true">
            <el-form-item>
              <el-radio-group v-model="show">
                <el-radio-button label="1">按主题</el-radio-button>
                <el-radio-button label="2">按单位</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="12" class="crud__right">
          <vxe-toolbar>
            <template v-slot:tools>
              <el-button icon="el-icon-refresh" @click="init()" circle></el-button>
            </template>
          </vxe-toolbar>
        </el-col>
      </div>
      <div>
        <fillingTask1 ref='fillingTask1' v-if="show === '1'" @showPrivilegeAudit="showPrivilegeAudit"
          v-bind:menuList="menuList" v-bind:deptList="deptList">
        </fillingTask1>
        <fillingTask2 ref='fillingTask2' v-if="show === '2'" @showPrivilegeAudit="showPrivilegeAudit"
          v-bind:deptList="deptList">
        </fillingTask2>
      </div>
    </el-card>
  </div>
</template>

<style lang="scss">
.pa .crud__menu {
  margin-bottom: 0px;
}
</style>

<script>
import fillingTask1 from './fillingTask1'
import fillingTask2 from './fillingTask2'
export default {
  data () {
    return {
      popoverVisable: false,
      defaultTreeProps: {
        label: 'name',
        children: 'children'
      },
      show: '1',
      menuList: [],
      deptList: [],
      IdListByIsImportant: [],
      dataForm: {}
    }
  },
  activated () {
    this.init()
  },
  methods: {
    init () {
      this.$nextTick(() => {
        Promise.all([
          this.getDeptList(),
          this.getMenuList()
        ]).then(() => {
        })
      })
    },
    // 切换组件
    showPrivilegeAudit (who) {
      this.show = who
    },
    // 获取菜单列表
    getMenuList () {
      return this.$http.get('/sys/menu/select').then(({ data: res }) => {
        if (res.code !== 0) {
          return
        }
        this.menuList = res.data
      }).catch(() => { })
    },
    // 获取部门列表
    getDeptList () {
      return this.$http.get('/sys/dept/list').then(({ data: res }) => {
        if (res.code !== 0) {
          return
        }
        this.deptList = this.$utils.treeDataTranslate(res.data)
      }).catch(() => { })
    },
    // 导出
    exportHandle () {
      if (this.show === '1') {
        this.$refs.privilegeAudit1.exportHandle()
      }
      if (this.show === '2') {
        this.$refs.privilegeAudit2.exportHandle()
      }
    }
  },
  components: {
    fillingTask1,
    fillingTask2
  }
}
</script>
